package com.google.common.collect;

import com.google.common.base.Preconditions;

import java.util.Collection;
import java.util.Iterator;

public class Iterators {
    public static <T> boolean addAll(Collection<T> addTo, Iterator<? extends T> iterator) {
        Preconditions.checkNotNull(addTo);
        Preconditions.checkNotNull(iterator);

        boolean wasModified;
        for(wasModified = false; iterator.hasNext(); wasModified |= addTo.add(iterator.next())) {
        }

        return wasModified;
    }
}
